package com.rybbaby.tss.api.activity;

import com.rybbaby.tss.core.bean.PageBean;
import com.rybbaby.tss.core.hqlsearch.HqlGenerateUtil;
import com.rybbaby.tss.core.utils.AppResponse;
import com.rybbaby.tss.core.web.controller.BaseController;
import com.rybbaby.tss.front.tssAppActivity.entity.TssAppActivity;
import com.rybbaby.tss.front.tssAppActivity.service.ITssAppActivityService;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping(value = "api/activity", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public class ActivityApi extends BaseController {
    @Autowired
    private ITssAppActivityService tssAppActivityService;
    /**
     * 获取活动列表
     *
     * @return
     * @throws
     */
    @CrossOrigin
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public String tssAppActivityList(TssAppActivity entity, PageBean paramPageBean) {
        String resMsg="查询成功";
        int resCode=200;
        PageBean pageBean=null;
        try {
            Map<String, String[]> unLockMap = getParameterMap(request);
            DetachedCriteria dc = DetachedCriteria.forClass(TssAppActivity.class);
            HqlGenerateUtil.fillDetachedCriteria(dc, entity, unLockMap);
            pageBean = tssAppActivityService.pageList(dc, paramPageBean.getPageNo(), paramPageBean.getPageSize());
        } catch (Exception e) {
            resMsg="查询失败";
            resCode=500;
            e.printStackTrace();
        }
        return new AppResponse(resMsg, resCode,pageBean).jsonResponse(true);
    }

}
